{include file='public/header'}
<body>
<div class="sectionY">
    {if empty($invite_code)}
    <a href="javascript:history.back()">
        <img src="__PUBLIC__/home/images/a19.png" alt="" class="a1">
    </a>
    {/if}
    <p class="p1">注册</p>
</div>
<div class="kong1"></div>
<div class="res_section1">
    <form action="" method="post">
        <div class="f1 clearfix">
            <img src="__PUBLIC__/home/images/login_icon_user.png" alt="">
            <input type="text" name="nick_name" class="input1" placeholder="请填写昵称">
        </div>
        <div class="f1 clearfix">
            <img src="__PUBLIC__/home/images/register_icon_phone.png" alt="" style="width:21px;left: 21px;">
            <input type="text" name="telephone" class="input1" placeholder="请填写手机号">
        </div>
        <div class="f1 clearfix">
            <img src="__PUBLIC__/home/images/login_icon_pw1.png" alt="">
            <input type="text" name="vcode" class="input1" placeholder="请填写验证码">
            <span class="sr_btn" id="getVcode">获取验证码</span>
        </div>
        <div class="f1 clearfix">
            <img src="__PUBLIC__/home/images/login_icon_pw.png" alt="" style="width:21px;left: 21px;">
            <input type="password" name="password" class="input1" placeholder="请填写密码">
        </div>
        <div class="f1 clearfix">
            <img src="__PUBLIC__/home/images/login_icon_pw.png" alt="" style="width:21px;left: 21px;">
            <input type="password" name="password1" class="input1" placeholder="请确认密码">
        </div>
        <div class="f1 clearfix">
            <img src="__PUBLIC__/home/images/a1.png" alt="">
            <input type="text" name="invite_code" value="{$invite_code|default=''}" class="input1" placeholder="请填写邀请码">
        </div>
        <div class="sub">
            <input type="button" value="注册" id="register">
        </div>
    </form>
</div>
</body>
<script>
    var invite = "{$invite_code}".trim();
    $(function () {
        $("#getVcode").on('click', function () {
            let telephone = $.trim($("input[name='telephone']").val());
            if (telephone == "") {
                modal.msg("请输入手机号")
                return;
            }
            let o = this;
            $(o).attr("disabled");
            let sec = 60;
            $.post('{:url("getVcode")}', {telephone: telephone, type: 1}, function (res) {
                modal.msg(res.result_info);
                if (res.result_code == 0) {
                    let i = setInterval(function () {
                        $(o).html(sec + "秒");
                        sec--;
                        if (sec < 1) {
                            clearInterval(i);
                            $(o).html("获取验证码");
                            $(o).removeAttr("disabled");
                        }
                    }, 1000);
                } else {
                    $(o).removeAttr("disabled");
                }
            });
        })
        $("#register").on("click", function () {
            let data = {},
                nick_name = $.trim($("input[name='nick_name']").val()),
                telephone = $.trim($("input[name='telephone']").val()),
                vcode = $.trim($("input[name='vcode']").val()),
                password = $.trim($("input[name='password']").val()),
                password1 = $.trim($("input[name='password1']").val()),
                invite_code = $.trim($("input[name='invite_code']").val());
            if (nick_name == "") {
                modal.msg("用户昵称不能为空");
                return;
            }
            data.nick_name = nick_name;
            if (telephone == "") {
                modal.msg("手机号不能为空");
                return;
            }
            data.telephone = telephone;
            if (vcode == "") {
                modal.msg("验证码不能为空")
                return
            }
            data.vcode = vcode;
            if (password == "" || !(password.length >= 6 && password.length <= 18)) {
                modal.msg("密码格式不正确，请使用6-18位密码");
                return;
            }
            if (password != password1) {
                modal.msg("两次密码不一致");
                return;
            }
            data.password = password;
            if (invite_code == "") {
                modal.msg("邀请码不能为空");
            }
            data.invite_code = invite_code;
            $.post("{:url('register')}", data, function (res) {
                modal.msg(res.result_info);
                if(res.result_code == 0){

                    if(invite != ''){
                        setTimeout(function () {
                            location.href='http://jiancai.sdliumaikeji.com/home/Index/app_register';
                        },666)
                    }else{
                        setTimeout(function () {
                            location.href="http://jiancai.sdliumaikeji.com/home/Index/login";
                        },666)
                    }
                }
            });
        })
    })
</script>
</html>